import {createPinia} from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import {useBusinessCodeStore} from '@/stores/modules/businessCode.store'
import {useWebConfigStore} from '@/stores/modules/webConfig.store'
import {useNavTabsStore} from '@/stores/modules/navTabs.store'
import {useUserStore} from '@/stores/modules/user.store'
import {cloneDeep} from 'lodash-es'
import {useAuthorityStore} from '@/stores/modules/authority.store'
import {useAppStore} from '@/stores/modules/app.store'
import {useUserCacheStore} from '@/stores/modules/userInfo.store'
import {useRouteParamsStore} from '@/stores/modules/routeParams.store'
import {useOssStore} from '@/stores/modules/oss.store'

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
pinia.use(({store}) => {
	const initialState = cloneDeep(store.$state)
	store.$reset = () => {
		store.$patch(initialState)
	}
})

export const resetAllStore = () => {
	useAppStore().resetAppStore()
	useOssStore().resetOssStore()
	useAuthorityStore().resetAuthorityStore()
	useBusinessCodeStore().resetBusinessCodeStore()
	useWebConfigStore().resetWebConfigStore()
	useNavTabsStore().resetNavTabsStore()
	useRouteParamsStore().resetRouteParamsStore()
	useUserCacheStore().resetUserInfoStore()
	useUserStore().resetUserStore()
}

export default pinia
